using System;
using System.Collections.Generic;


namespace HEFramework
{
    /// <summary>
    ///
    /// 列表对象
    /// 
    /// ----------------------------------------
    /// 作者 hep
    /// 创建时间：2023-12-11 13:43:14
    /// ----------------------------------------
    /// </summary>
    public class ListObject<T> : List<T>, IDisposable
    {
        private bool IsDispose { get; set; }

        public ListObject()
        {
        }

        /// <summary>
        /// 结合using使用来释放列表
        /// </summary>
        /// <returns></returns>
        public static ListObject<T> Create()
        {
            var list = ObjectGenerater.Instance.Fetch(typeof(ListObject<T>)) as ListObject<T>;
            list.IsDispose = false;
            return list;
        }

        public void Dispose()
        {
            if (!IsDispose)
            {
                this.Clear();
                ObjectGenerater.Instance.Recycle(this);
                IsDispose = true;
            }
        }
    }
}